home *** CD-ROM | disk | FTP | other *** search
- {*******************************************************************************
- ** PROGRAMMING by: DEREK CRIBBS Date: 03/18/93 **
- ** **
- ** SndPlayMidi - simple function to play a midi file similar to sndplaysound **
- ** for .WAV files. **
- ** **
- ** I wrote this little Unit to help BPW users like myself. **
- ** Since I was looking for some code to do this before I wrote it, I figured **
- ** the least I could do was save you all some time, by giving you a start **
- ** with my efforts, I used the multimedia programmers workbook for reference **
- ** **
- ** **
- ** If (you like it) then **
- ** begin **
- ** keep_it; **
- ** use_it; **
- ** pass_it_on; **
- ** end **
- ** else **
- ** trash_it; **
- ** **}
- unit midi;
- interface
- uses wintypes,Winprocs,MMSystem,win31,strings;
- function SndPlayMidi(HWndNotify:Hwnd;lpszMIDIFilename:Pchar):LongInt;
- implementation
- function SndPlayMidi(HWndNotify:Hwnd;lpszMIDIFilename:Pchar):LongInt;
- type
- MCI_OPEN_PARMS = TMCI_Open_Parms;
- MCI_SET_PARMS = TMCI_Set_Parms;
- MCI_PLAY_PARMS = TMCI_Play_Parms;
- MCI_STATUS_PARMS = TMCI_Status_Parms;
- MCI_SEQ_SET_PARMS = TMCI_Seq_Set_Parms;
- var
- wDeviceId:word;
- dwReturn :LongInt;
- mciOpenParms : MCI_OPEN_PARMS;
- mciPlayParms : MCI_PLAY_PARMS;
- mciStatusParms : MCI_STATUS_PARMS;
- mciSeqSetParms : MCI_SEQ_SET_PARMS;
- astring:string;
- begin
- {choose midi sequencer}
- mciOpenParms.lpstrDeviceType := 'SEQUENCER';
- mciOpenParms.lpstrElementName:= lpszMIDIFileName;
- Dwreturn:=mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE or MCI_OPEN_ELEMENT,
- Longint(@MCIOPENPARMS));
- wDeviceId:=MCIOPENPARMS.wDeviceId;
- mciStatusParms.dwitem:=MCI_SEQ_STATUS_PORT;
- DwReturn:=mciSendCommand(WDeviceID,MCI_STATUS,MCI_STATUS_ITEM,Longint(@MCISTATUSPARMS));
- if DwReturn<>0 then
- begin
- mcisendcommand(wDeviceID,MCI_CLOSE,0,0);
- SndPlayMidi:=dwReturn;
- end;
-
- { Uncomment this to check for MIDIMAPPER I just leave it commented for my purposes
-
- if LoWord(mciStatusParms.DwReturn) <> MIDIMAPPER then
- begin
- mciSendCommand(wDeviceID, MCI_CLOSE,0,0);
- SndPlayMidi:=0;
- end;}
-
- mciPlayParms.dwCallBack:=LongInt(hWndNotify);
- DwReturn:=mciSendCommand(WDeviceID,MCI_PLAY,MCI_NOTIFY,Longint(@MCISTATUSPARMS));
- if DwReturn<>0 then
- begin
- mcisendcommand(wDeviceID,MCI_CLOSE,0,0);
- SndPlayMidi:=dwreturn;
- end;
- SndPlayMidi:=0;
- end;
- end.